//
//  LGKNoteMainModel.m
//  LGKNote
//
//  Created by 刘亚军 on 2023/5/26.
//

#import "LGKNoteMainModel.h"
#import <YJExtensions/YJEHpple.h>
#import "LGKConst.h"
@implementation LGKNoteMainModel
- (void)setNoteContent:(NSString *)NoteContent{
    _NoteContent = NoteContent;
    if (!IsStrEmpty(NoteContent)){
        NSData *data = [NoteContent dataUsingEncoding:NSUTF8StringEncoding];
        YJEHpple *hpple = [[YJEHpple alloc] initWithHTMLData:data];
        NSArray *imgArr = [hpple searchWithXPathQuery:@"//img"];
        if (!IsArrEmpty(imgArr)){
            _imgUrlArr = [imgArr yj_map:^id _Nonnull(YJEHppleElement *element) {
                return [element.attributes objectForKey:@"src"];
            }];
        }
        _filterStr = [NSString yj_filterHTML:NoteContent.yj_htmlDecode].yj_deleteWhitespaceAndNewlineCharacter;
        _mixTextImage = !IsArrEmpty(_imgUrlArr) && _filterStr.length > 0;
    }
}
@end
